#!/bin/bash

set -e
set -x

bypy download mariadb-10.5.27-linux-systemd-x86_64.tar.gz
tar xf mariadb-10.5.27-linux-systemd-x86_64.tar.gz -C /usr/local/
mv /usr/local/mariadb-10.5.27-linux-systemd-x86_64 /usr/local/mysql
useradd -M -s /sbin/nologin  mysql
mkdir /usr/local/mysql/data/
mkdir /var/lib/mysql/
mkdir /var/log/mysql/
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /var/log/mysql
/usr/local/mysql/scripts/mysql_install_db -u mysql --ldata=/usr/local/mysql/data/

cp ./one/my.cnf /etc/
cp /usr/local/mysql/support-files/systemd/mariadb.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mariadb.service
ln -fs /usr/local/mysql/bin/mysql /usr/bin/
yum install -y ncurses-compat-libs

sleep 5
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Abc_123456';FLUSH PRIVILEGES;"
mysql -uroot -p'Abc_123456' -e "CREATE USER 'root'@'%' IDENTIFIED BY 'Abc_123456';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';FLUSH PRIVILEGES;"


set +x
set +e
